__________________________________________________________________________________________________
4ms
class Solution {
public:
    int numTrees(int n) {
        int d[n+1] = {0};
        d[0] = 1;
        d[1] = 1;
        for (int i = 2; i <= n; ++i) {
            d[i] = 0;
            for (int k = 0; k <= i-1; ++k) {
                d[i] += d[k]*d[i-1-k];
            }
        }
        return d[n];
    }
};
__________________________________________________________________________________________________
7972 kb
class Solution {
public:
    int numTrees(int n) {
        int dp[n+1];
        dp[0] = dp[1] = 1;
        for (int i=2; i<=n; i++) {
            dp[i] = 0;
            for (int j=1; j<=i; j++) {
                dp[i] += dp[j-1] * dp[i-j];
            }
        }
        return dp[n];
    }
};
__________________________________________________________________________________________________
